﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：WF_TYPE实体层次
//********************************************************************************//

#region Entity

using System;
using System.Data;
using Entity;
using Oracle.DataAccess.Client;
using Platform.Configuration;
using Platform.Data;

namespace Entity
{
    [Serializable]
    public class WF_TYPE
    {
        private decimal m_dec_i_liuchengid;

        private string m_str_s_beizhu;

        private string m_str_s_liuchenglb;

        private string m_str_s_liuchengmc;

        /// <summary>
        ///     流程ID
        /// </summary>
        public decimal I_LIUCHENGID
        {
            get { return m_dec_i_liuchengid; }
            set { m_dec_i_liuchengid = value; }
        }

        /// <summary>
        ///     流程类别
        /// </summary>
        public string S_LIUCHENGLB
        {
            get { return m_str_s_liuchenglb; }
            set { m_str_s_liuchenglb = value; }
        }

        /// <summary>
        ///     流程名称
        /// </summary>
        public string S_LIUCHENGMC
        {
            get { return m_str_s_liuchengmc; }
            set { m_str_s_liuchengmc = value; }
        }

        /// <summary>
        ///     备注
        /// </summary>
        public string S_BEIZHU
        {
            get { return m_str_s_beizhu; }
            set { m_str_s_beizhu = value; }
        }
    }
}

#endregion

#region EntityProcess

namespace BLL.Access
{
    //using System.Data.OracleClient;

    public class WF_TYPEProcess
    {
        #region Field

        protected string conn;

        #endregion

        #region Construction

        public WF_TYPEProcess()
        {
            conn = ConfigHelper.PlatformConnString;
        }

        #endregion

        #region public

        /// <summary>
        ///     根据WF_TYPE实体添加或者修改WF_TYPE信息
        /// </summary>
        public bool InsertOrUpdate(WF_TYPE WF_TYPE, OracleTransaction Transaction)
        {
            if (WF_TYPE.I_LIUCHENGID == 0)
                InsertWF_TYPE(WF_TYPE, Transaction);
            else
                UpdateWF_TYPE(WF_TYPE, Transaction);
            return WF_TYPE.I_LIUCHENGID == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_TYPE实体添加或修改WF_TYPE信息
        /// </summary>
        public bool InsertOrUpdate(WF_TYPE WF_TYPE)
        {
            return InsertOrUpdate(WF_TYPE, null);
        }


        /// <summary>
        ///     根据WF_TYPE主键删除WF_TYPE信息
        /// </summary>
        /// <param name="I_LIUCHENGID"></param>
        public bool DeleteWF_TYPE(decimal I_LIUCHENGID, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_TYPE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_LIUCHENGID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据WF_TYPE主键删除WF_TYPE信息
        /// </summary>
        /// <param name="I_LIUCHENGID"></param>
        public bool DeleteWF_TYPE(decimal I_LIUCHENGID)
        {
            return DeleteWF_TYPE(I_LIUCHENGID, null);
        }

        /// <summary>
        ///     根据条件删除WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_TYPEsDynamic(string WhereClause, OracleTransaction Transaction)
        {
            var spName = "CS_DelWF_TYPEsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        ///     根据条件删除WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteWF_TYPEsDynamic(string WhereClause)
        {
            return DeleteWF_TYPEsDynamic(WhereClause, null);
        }

        /// <summary>
        ///     根据WF_TYPE主键选择WF_TYPE信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_TYPE信息</returns>
        public WF_TYPE SelectWF_TYPE(decimal I_LIUCHENGID, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_TYPE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = I_LIUCHENGID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                var WF_TYPE = PopulateWF_TYPE(rd);
                rd.Close();
                return WF_TYPE;
            }
            return null;
        }

        /// <summary>
        ///     根据WF_TYPE主键选择WF_TYPE信息
        /// </summary>
        /// <returns>WF_TYPE信息</returns>
        public WF_TYPE SelectWF_TYPE(decimal I_LIUCHENGID)
        {
            return SelectWF_TYPE(I_LIUCHENGID, null);
        }

        /// <summary>
        ///     选择所有WF_TYPE信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsAll(OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_TYPEsAll";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }

        /// <summary>
        ///     选择所有WF_TYPE信息
        /// </summary>
        /// <returns>所有WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsAll()
        {
            return SelectWF_TYPEsAll(null);
        }

        /// <summary>
        ///     根据条件选择WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsDynamic(string WhereClause, string OrderByExpression,
            OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_TYPEsDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectWF_TYPEsDynamic(WhereClause, OrderByExpression, null);
        }


        /// <summary>
        ///     根据条件选择WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize, OracleTransaction Transaction)
        {
            var spName = "CS_SelWF_TYPEsDynPaged";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            return null;
        }


        /// <summary>
        ///     根据条件选择WF_TYPE信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>WF_TYPE信息</returns>
        public DataTable SelectWF_TYPEsDynamic(string WhereClause, string OrderByExpression, int PageIndex,
            int PageSize)
        {
            return SelectWF_TYPEsDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///     根据条件更新WF_TYPE字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_TYPEsDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            var result = 0;
            if (UpdateValue == "" || WhereClause == "")
                return 0;
            var spName = "CS_UpdWF_TYPEDyn";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset(Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///     根据条件更新WF_TYPE字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateWF_TYPEsDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateWF_TYPEsDynamic(UpdateValue, WhereClause, null);
        }

        #endregion

        #region Private

        private int InsertWF_TYPE(WF_TYPE WF_TYPE, OracleTransaction Transaction)
        {
            var spName = "CS_InsWF_TYPE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_TYPE.S_LIUCHENGLB;
            storedParams[1].Value = WF_TYPE.S_LIUCHENGMC;
            storedParams[2].Value = WF_TYPE.S_BEIZHU;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            WF_TYPE.I_LIUCHENGID = Convert.ToInt32(storedParams[3].Value);
            return result;
        }

        private bool UpdateWF_TYPE(WF_TYPE WF_TYPE, OracleTransaction Transaction)
        {
            var spName = "CS_UpdWF_TYPE";
            var storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WF_TYPE.S_LIUCHENGLB;
            storedParams[1].Value = WF_TYPE.S_LIUCHENGMC;
            storedParams[2].Value = WF_TYPE.S_BEIZHU;
            storedParams[3].Value = WF_TYPE.I_LIUCHENGID;
            var result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery(Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private WF_TYPE PopulateWF_TYPE(IDataReader dr)
        {
            var WF_TYPE = new WF_TYPE();
            WF_TYPE.I_LIUCHENGID = dr["I_LIUCHENGID"] == DBNull.Value ? 0 : (decimal) dr["I_LIUCHENGID"];
            WF_TYPE.S_LIUCHENGLB = dr["S_LIUCHENGLB"] == DBNull.Value ? "" : (string) dr["S_LIUCHENGLB"];
            WF_TYPE.S_LIUCHENGMC = dr["S_LIUCHENGMC"] == DBNull.Value ? "" : (string) dr["S_LIUCHENGMC"];
            WF_TYPE.S_BEIZHU = dr["S_BEIZHU"] == DBNull.Value ? "" : (string) dr["S_BEIZHU"];
            return WF_TYPE;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (var i = 0; i < dt.Rows.Count; i++)
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
        }

        #endregion
    }
}

#endregion